home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / snip9_91.arc / CPUCHECK.ASM < prev    next >
Assembly Source File  |  1991-09-17  |  2KB  |  58 lines

  1. ;  FUNCTION:  cpu_check
  2. ;
  3. ;  Attempt to discover the type of CPU. Use MASM 5.1 or greater.
  4. ;  Returns 86 for 8088/8086, 286 for 80286, 386 for 80386/80486.
  5.  
  6.         page    55, 132
  7.  
  8. %       .MODEL  memodel,C               ;Add model support via
  9.                                         ;command line macros, e.g.
  10.                                         ;MASM /Dmemodel=LARGE
  11.  
  12.         .CODE
  13. ;
  14. ; int cpu_check(void) - returns 86, 186, 286, 386
  15. ;
  16.  
  17.     PUBLIC    cpu_check
  18.  
  19. cpu_check       PROC    USES BX
  20.         pushf
  21.         xor     ax,ax                   ; zero ax
  22.         push    ax
  23.         popf                            ; try to put 0 into flags
  24.         pushf
  25.         pop     ax                      ; see what went in flags
  26.         and     ax,0f000h               ; mask off high flag bits
  27.         cmp     ax,0f000h               ; was high nibble ones
  28.         je      _86                     ; is 8086 or 8088
  29.         push    sp                      ; see if sp is updated
  30.         pop     bx                      ; before or after it is
  31.         cmp     bx,sp                   ; pushed
  32.         jne     _186
  33.         mov     ax,0f000h               ; try to set high bits
  34.         push    ax
  35.         popf                            ; in the flags
  36.         pushf
  37.         pop     ax                      ; look at actual flags
  38.         and     ax,0f000h               ; any high bits set?
  39.         je      _286                    ; is 80286
  40. _386:
  41.         mov     ax,386                  ; is an 80386
  42.         jmp     ccexit
  43. _286:
  44.         mov     ax,286                  ; is an 80286
  45.         jmp     ccexit
  46. _186:
  47.         mov     ax,186                  ; is an 80188/80186
  48.         jmp     ccexit
  49. _86:
  50.         mov     ax,86                   ; is an 8088/8086
  51. ccexit:
  52.         popf                            ; restore original flags
  53.         ret                             ; return
  54.  
  55. cpu_check       ENDP    
  56.  
  57.         end
  58.